import { isAccountExist } from '@/api/demo/system';
import { BasicColumn, FormSchema } from '@/components/Table';

export const columns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'oid',
    width: 100,
  },
  {
    title: '客户编号',
    dataIndex: 'tid',
    width: 120,
  },
  {
    title: '所属人员',
    dataIndex: 'suoShuRenYuanName',
    width: 100,
  },

  {
    title: '所属部门',
    dataIndex: 'qyname',
    width: 120,
  },
  {
    title: '所属地区',
    dataIndex: 'suoZaiQuYuName',
    width: 120,
  },
  {
    title: '市场区域',
    dataIndex: 'diQuNAME',
    width: 120,
  },
  // {
  //   title: '离职时间',
  //   dataIndex: 'dimissionTime',
  //   width: 180,
  // },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '搜索',
    component: 'Input',
    componentProps: {
      placeholder: '请输入编号/名称',
    },
    colProps: { span: 6 },
  },
  // {
  //   field: 'dname',
  //   label: '部门',
  //   component: 'Input',
  //   colProps: { span: 6 },
  // },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'account',
    label: '用户名',
    component: 'Input',
    helpMessage: ['本字段演示异步验证', '不能输入带有admin的用户名'],
    rules: [
      {
        required: true,
        message: '请输入用户名',
      },
      {
        trigger: 'blur',
        validator(_, value) {
          return new Promise((resolve, reject) => {
            if (!value) return resolve();
            isAccountExist(value)
              .then(resolve)
              .catch((err) => {
                reject(err.message || '验证失败');
              });
          });
        },
      },
    ],
  },
  {
    field: 'pwd',
    label: '密码',
    component: 'InputPassword',
    required: true,
    ifShow: false,
  },
  {
    field: 'dept',
    label: '所属部门',
    component: 'TreeSelect',
    componentProps: {
      fieldNames: {
        label: 'deptName',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
    required: true,
  },
  {
    field: 'nickname',
    label: '昵称',
    component: 'Input',
    required: true,
  },

  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    required: true,
  },

  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];
